#include "common.h"
#include "log.h"

#include <stdio.h>
#include <stdlib.h>

void ex_log(LogLevel level, const char *format, ...)
{
    va_list args;

    va_start(args, format);

    switch (level) {
    case LOG_LEVEL_INFO:
        printf("[INFO]: ");
        break;
    case LOG_LEVEL_WARNING:
        printf("[WARNING]: ");
        break;
    case LOG_LEVEL_ERROR:
        printf("[ERROR]: ");
        break;
    case LOG_LEVEL_TRACE:
        printf("[TRACE]: ");
        break;
    case LOG_LEVEL_DEBUG:
        printf("[DEBUG]: ");
        break;
    case LOG_LEVEL_FATAL:
        printf("[FATAL]: ");
        break;
    default:
        break;
    }

    vprintf(format, args);

    va_end(args);
    printf("\n");

    if (LOG_LEVEL_FATAL == level) {
        abort();
    }
}

void die(const char *format, ...)
{
    va_list ap;
    va_start(ap, format);
    fputs("[FATAL]: ", stderr);
    vfprintf(stderr, format, ap);
    fputs("\n", stderr);
    abort();
}
